<?php



class user_model extends Model
{
    private static $members = array();

    public function register($param)
    {
        $param['password'] = md5($param['password']);
        $param['add_time'] = time();

        return $this->create($param);
    }

    public function update_info($user_id, $param)
    {
        return $this->update(array('id'=>$user_id), $param);
    }

    // get userinfo by id/ids
    public function getInfoById($member_id)
    {
        $member_id = (array)$member_id;
        $ids = array();
        $out = array();
        foreach ($member_id as $key => $val) {
            if (isset(self::$members[$val])) {
                $out[$val] = self::$members[$val];
            } else {
                $out[$val] = array();
                $ids[] = $val;
            }
        }

        if ($ids) {
            $table = $this->table;
            $sql = "SELECT * FROM `$table` WHERE id IN('".implode("', '", $member_id)."')";
            $result = $this->db->getAll($sql);
            foreach ($result as $key => $val) {
                $out[$val['id']] = $val;
                self::$members[$val['id']] = $val;
            }
        }

        return count($out) == 1 ? reset($out) : $out;
    }

    // get userinfo by name
    public function getInfoByName($name)
    {
        static $members = array();
        if (!isset($members[$name])) {
            $t = $this->read(array('user_name'=>$name));

            $members[$name] = $t;
        }

        return $members[$name];
    }
    
    // get userinfo by name
    public function getInfoByEmail($name)
    {
        static $members = array();
        if (!isset($members[$name])) {
            $t = $this->read(array('email'=>$name));

            $members[$name] = $t;
        }

        return $members[$name];
    }
}


?>